package javaapplication7;

import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class IxDatasourceIdConstants {

    public static Map<String, String> nodeMap;
    public static Map<String, Map> displayNameMap;
public static Map<String, String> tempMap;

    public static void main(String[] args) {
        String source = "hai_voc.xml";
        try {

            displayNameMap = new HashMap<String, Map>();
            InputStream inputStream = IxDatasourceIdConstants.class.getClassLoader().getResourceAsStream(source);

            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(inputStream);

            doc.getDocumentElement().normalize();
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////

            NodeList nListSystem = doc.getElementsByTagName("system");

            for (int k = 0; k < nListSystem.getLength(); k++) {
                nodeMap = new HashMap<String, String>();
                tempMap = new HashMap<String, String>();
                
                Node nNodeSystem = nListSystem.item(k);

                if (nNodeSystem.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElementSystem = (Element) nNodeSystem;
                    NodeList nList = eElementSystem.getElementsByTagName("code");

                    for (int i = 0; i < nList.getLength(); i++) {
                        Node nNode = nList.item(i);

                        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                            Element eElement = (Element) nNode;
                            nodeMap.put(eElement.getAttribute("value"),
                                    eElement.getAttribute("displayName"));
                        }
                    }
                    displayNameMap.put(eElementSystem.getAttribute("valueSetName"), nodeMap);
                    tempMap.put(eElementSystem.getAttribute("valueSetName"), eElementSystem.getAttribute("valueSetOid"));
                    System.out.println(tempMap);
//                    System.out.println(displayNameMap);
//                    System.out.println(displayNameMap.size());
//                    displayNameMap.clear();
                }
            }
        } catch (Exception e) {
            e.printStackTrace(); //?????????????
        }
        System.out.println(displayNameMap);
        System.out.println(displayNameMap.size());
        
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z");
Date date = new Date();
System.out.println(dateFormat.format(date));
        
    }
}
